import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void testInsert(int[] array) {
        long start = System.currentTimeMillis();
        TestSort.insertSort(array);
        long end = System.currentTimeMillis();
        System.out.println("插入排序耗时：" + (end-start));
    }

    public static void testShellSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        TestSort.shellSort(array);
        long end = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (end-start));
    }

    public static void testSelectSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        TestSort.selectSort(array);
        long end = System.currentTimeMillis();
        System.out.println("选择排序耗时：" + (end-start));
    }
    public static void testSelectSort2(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        TestSort.selectSort2(array);
        long end = System.currentTimeMillis();
        System.out.println("选择排序2耗时：" + (end-start));
    }

    public static void heapSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        TestSort.heapSort(array);
        long end = System.currentTimeMillis();
        System.out.println("堆排序耗时：" + (end-start));
    }

    public static void bubbleSort(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        TestSort.bubbleSort(array);
        long end = System.currentTimeMillis();
        System.out.println("冒泡排序耗时：" + (end-start));
    }

    //将数组初始化为有序的数据
    public static void initOrder(int[] array) { //先给数组赋值
        for (int i = 0; i < array.length; i++) {
            array[i] = i; //有序的直接插入比希尔快
//            array[i] = array.length-i; //逆序的希尔比直接插入快
        }
    }

    //将数组初始化为无序的数据
    public static void initNotOrder(int[] array) { //无序的数组
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        initOrder(array); //时间快
//        initNotOrder(array); //时间慢
        testInsert(array);
        testShellSort(array);
//        testSelectSort(array);
//        testSelectSort2(array);
        heapSort(array);
        bubbleSort(array);
    }
}
